package com.heima.controller;

import com.github.pagehelper.PageInfo;
import com.heima.domain.Orders;
import com.heima.service.OrdersService;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.security.RolesAllowed;
import java.util.List;

@Controller
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersService service;
    @RequestMapping("/findAll")

    public String findAll(Model model,
                          @RequestParam(value = "page",required = true,defaultValue = "1") Integer page,
                          @RequestParam(value = "pageSize",required = true,defaultValue = "3")Integer pageSize)
    {
       List<Orders> orders=service.findAll(page,pageSize);

      /* for(Orders order:orders){
           System.out.println(order);
           System.out.println(order.getProduct());
       }*/
        PageInfo<Orders> pageInfo=new PageInfo<Orders>(orders);
        System.out.println(pageInfo);
        model.addAttribute("pageInfo",pageInfo);
        return "orders-list";
    }
   @RequestMapping("/findById")
    public String findById(Model model,@RequestParam(name ="id",required = true) String id){
        Orders orders=service.findById(id);
        System.out.println(orders);
        model.addAttribute("orders",orders);
        return "orders-show";
    }
}
